//
//  MYGWhoSeeCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/19.
//

import UIKit

class MYGWhoSeeCell: UITableViewCell {
    // MARK: - Property
    var model: MYGWhoSeeModel? {
        didSet {
            guard let model = model else {
                return
            }
            
            if let title = model.title, !title.isEmpty {
                titleLabel.isHidden = false
                titleLabel.text = title
            } else {
                titleLabel.isHidden = true
            }
            
            nameLabel.text = model.name
            
            selectImageView.isHidden = !model.isSel
        }
    }
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - UI
    private func configUI() {
        contentView.addSubview(stackView)
        contentView.addSubview(lineView)
        contentView.addSubview(selectImageView)
        stackView.addArrangedSubviews([titleLabel, nameLabel])
        
        stackView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(26)
            make.top.equalToSuperview().offset(9)
            make.bottom.equalToSuperview().inset(9)
        }
        
        selectImageView.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(36)
            make.centerY.equalToSuperview()
        }
        
        lineView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(26)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }

    
    // MARK: - lazy load
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .vertical
        stackV.spacing = 2
        return stackV
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .rgba(51, 51, 51, 1)
        return label
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(14)
        label.textColor = .rgba(51, 51, 51, 1)
        return label
    }()
    
    private lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .rgba(238, 238, 238, 1)
        return view
    }()
    
    private lazy var selectImageView: UIImageView = {
        let imgV = UIImageView(image: UIImage(named: "Common/sel"))
        return imgV
    }()
}
